/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package JFreeChartExtensions.chartextensions.utils;

import java.awt.Color;
import java.awt.Rectangle;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseEvent;
import java.awt.geom.Rectangle2D;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;

/**
 *
 * @author Nobody
 */
public class InsetChartPanel extends ChartPanel implements ComponentListener {
    private Rectangle2D.Double lastBounds;

    public Rectangle2D.Double getLastBounds() {
        return lastBounds;
    }

    public void setLastBounds(Rectangle2D.Double lastBounds) {
        this.lastBounds = lastBounds;
    }

    @Override
    public void componentHidden(ComponentEvent e) {
    }

    @Override
    public void componentMoved(ComponentEvent e) {
    }

    @Override
    public void componentResized(ComponentEvent e) {
       
    }

    @Override
    public void componentShown(ComponentEvent e) {
    }

    public InsetChartPanel(JFreeChart chart) throws CloneNotSupportedException {
        super((JFreeChart) chart.clone());
        clearAllChartDecorations();
        enableBorderTransparency();
    }

    public void setBoundsAndRepaint(Rectangle rect) {
    }

    @Override
    public void revalidate() {
        super.revalidate();
    }

    @Override
    public void setBounds(int x, int y, int width, int height) {
        super.setBounds(x, y, width, height);
    }

    @Override
    public void setBounds(Rectangle r) {
        super.setBounds(r);
    }

    private void clearAllChartDecorations() {
        JFreeChart chart = getChart();
        chart.clearSubtitles();
        chart.setTitle("");
        chart.getXYPlot().getDomainAxis().setLabel("");
        chart.getXYPlot().getRangeAxis().setLabel("");
        chart.removeLegend();
    }

    private void enableBorderTransparency() {
        JFreeChart chart = getChart();
        chart.setBackgroundPaint(new Color(0, 0, 0, 0));
        chart.setBackgroundImageAlpha(0.0f);
        setBackground(new Color(0, 0, 0, 0));
    }

    @Override
    public void mouseClicked(MouseEvent event) {
    }

    @Override
    public void mousePressed(MouseEvent e) {
    }

    @Override
    public void mouseReleased(MouseEvent e) {
    }

    public void setChartAsCopy(JFreeChart chart) throws CloneNotSupportedException {

        setChart((JFreeChart) chart.clone());
        clearAllChartDecorations();
        enableBorderTransparency();

    }

    public void setLastBounds(double x, double y, double width, double height) {
        setLastBounds(new Rectangle2D.Double(x, y, width, height));
    }
}
